import { onMounted } from 'vue'

export default () => {
  let _listenerDom = []

  let obs = new IntersectionObserver((e) => {
    e.map((x) => {
      if (x.isIntersecting) {
        x.target.src = x.target.attributes['data-src'].value
        x.target.attributes['data-loaded'].value = 'true'
        obs.unobserve(x.target)
      }
    })
  })

  let add = (el) => {
    if (el == undefined) return
    //_listenerDom.push(el)
    obs.observe(el)
  }

  return { add }
}
